package vb.week2.tabular;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;

import vb.week2.tabular.Token.Kind;

public class ParserEmit extends Parser
{
  public ParserEmit(Scanner scanner)
  {
    super(scanner);
  }

  /**
   * @param args
   */
  public static void main(String[] args)
  {
    FileInputStream is = null;
    try
    {
      is = new FileInputStream(new File("sample-3.tex"));
    }
    catch (FileNotFoundException e)
    {
      e.printStackTrace();
    }
    Scanner scanner = new Scanner(is);
    ParserEmit p = new ParserEmit(scanner);
    System.out.println(p.parse());
  }

  @Override
  public boolean parse()
  {
    System.out.println("<html><body>");
    boolean result = super.parse();
    System.out.println("</body></html>");
    return result;
  }

  @Override
  protected void parseEntry() throws SyntaxErrorException
  {
    System.out.print("\t<td>" + currentToken.getRepr());
    super.parseEntry();
    System.out.println("</td>");
  }

  @Override
  protected void parseLatexTabular() throws SyntaxErrorException
  {
    System.out.println("<table>");
    super.parseLatexTabular();
    System.out.println("</table>");
  }

  @Override
  protected void parseRows() throws SyntaxErrorException
  {
    while (currentToken.getKind() != Kind.BSLASH)
    {
      System.out.println("<tr>");
      parseEntries();
      System.out.println("</tr>");
      accept(Kind.DOUBLE_BSLASH);
    }
  }



}
